package com.wedding.mq;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class MQUtil {
	
	public static Connection getConnection() throws IOException, TimeoutException {
		//1.创建一个ConnectionFactory 并进行配置
		ConnectionFactory connectionFactory = new ConnectionFactory();
		connectionFactory.setHost("127.0.0.1");
		connectionFactory.setPort(5672);
		connectionFactory.setVirtualHost("/");
		connectionFactory.setUsername("guest");
		connectionFactory.setPassword("guest");
		connectionFactory.setHandshakeTimeout(20000);
		//2.通过连接工厂创建连接
		Connection connection = connectionFactory.newConnection();
		return connection;
	}
	
}
